home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / SNIP9_91.ARJ / PRTOGGLE.C < prev    next >
C/C++ Source or Header  |  1991-09-12  |  880b  |  32 lines

  1. /*
  2. **  prtoggle()
  3. **
  4. **  Tee's all standard output to the printer.
  5. **
  6. **  Parameters: None
  7. **
  8. **  Returns:  0 if operation was successful.
  9. **           -1 if stdout or stdin is redirected.
  10. **
  11. **  Side effects: Flushes the keyboard buffer
  12. */
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <conio.h>
  17. #include <io.h>
  18. #ifdef __ZTC__          /* Zortech C/C++ doesn't support ungetch()      */
  19.  #include <mflsys.h>    /* Part of the MFLZT shareware library          */
  20. #endif
  21.  
  22. int cdecl prtoggle(void)
  23. {
  24.       if (!isatty(fileno(stdin)) || !isatty(fileno(stdout)))
  25.             return -1;
  26.       while (kbhit())           /* Flush the keyboard buffer            */
  27.             getch();
  28.       ungetch('P' - 64);        /* Stuff a Ctrl-P into the buffer       */
  29.       system("");               /* Let COMMAND.COM do the work          */
  30.       return 0;
  31. }
  32.